/*
   Alternative implementations of GCC compiler built-ins.
   Needed when not compiling with GCC.
   NOTE: This file is not a part of Pico SDK!
*/

#ifndef __GNUC__

/* Alternative implementation of __builtin_ctz */
int __ctz(unsigned int v)
{
int c = 0;

  if ((v & 0xffff) == 0) {
    v >>= 16;
    c += 16;
  }
  if ((v & 0xff) == 0) {
    v >>= 8;
    c += 8;
  }
  if ((v & 0xf) == 0) {
    v >>= 4;
    c += 4;
  }
  if ((v & 0x3) == 0) {
    v >>= 2;
    c += 2;
  }
  if ((v & 0x3) == 0x2) {
    c++;
  }
  return v ? c : -1;
}

#endif
